package com.demo.paypalmanagement.controller.admin;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.demo.paypalmanagement.common.BuildQuery;
import com.demo.paypalmanagement.common.ResultMsg;
import com.demo.paypalmanagement.config.response.BizException;
import com.demo.paypalmanagement.model.entity.OrderItems;
import com.demo.paypalmanagement.model.vo.OrderItemVO;
import com.demo.paypalmanagement.model.vo.Result;
import com.demo.paypalmanagement.service.IOrderItemsService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 订单项表，记录每个订单中的具体商品信息，如商品ID、数量、单价等 前端控制器
 * </p>
 *
 * @author dayu
 * @since 2024-12-02
 */
@RestController
@RequestMapping("/order-items")
public class OrderItemsController {

    @Autowired
    private IOrderItemsService orderItemsService;

    @GetMapping("/page")
    public IPage<OrderItems> getOrderItemPage(OrderItemVO vo) {
        if (ObjectUtils.isEmpty(vo)) {
            throw new BizException(ResultMsg.OBJECT_IS_EMPTY.getMsg());
        }

        Page<OrderItems> page = new Page<>(vo.getPageNo(), vo.getPageSize());

        return orderItemsService.page(page, BuildQuery.buildOrderItemQuery(vo));
    }


    @GetMapping("/remove")
    public Result removeOrderItems(OrderItemVO vo) {
        if (ObjectUtils.isEmpty(vo) || ObjectUtils.isEmpty(vo.getOrderId())) {
            throw new BizException(ResultMsg.LAST_ONE.getMsg());
        }
        return Result.success(orderItemsService.removeById(vo.getOrderItemId()));
    }

}
